package com.weetop.cfw.kind.activity

import android.annotation.SuppressLint
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.webkit.WebView
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager
import com.baidu.mapapi.map.BitmapDescriptorFactory.fromResource
import com.baidu.mapapi.map.MapStatus
import com.baidu.mapapi.map.MapStatusUpdateFactory
import com.baidu.mapapi.map.MapView
import com.baidu.mapapi.map.MarkerOptions
import com.baidu.mapapi.model.LatLng
import com.baidu.mapapi.search.core.SearchResult
import com.baidu.mapapi.search.geocode.*
import com.blankj.utilcode.util.*
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.coorchice.library.SuperTextView
import com.gyf.immersionbar.ImmersionBar
import com.kongzue.dialog.v3.BottomMenu
import com.kongzue.dialog.v3.MessageDialog
import com.stx.xhb.xbanner.XBanner
import com.weetop.cfw.MainActivity
import com.weetop.cfw.R
import com.weetop.cfw.base.presenter.imp.WorkshopDetailPresenterImp
import com.weetop.cfw.base.ui.activity.CommonBaseActivity
import com.weetop.cfw.base.view.WorkshopDetailView
import com.weetop.cfw.bean.LeaseSaleBrowsingRecordBean
import com.weetop.cfw.bean.PermisssionBean
import com.weetop.cfw.bean.TestBean
import com.weetop.cfw.bean.WorkshopWarehouseDetailBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.constants.Constants
import com.weetop.cfw.constants.UrlConstants
import com.weetop.cfw.home_page.activity.TouSuActivity
import com.weetop.cfw.kind.adapter.WorkshopDetailAdapter
import com.weetop.cfw.mine.activity.PurchaseMembershipActivity
import com.weetop.cfw.other.CommonWebViewActivity
import com.weetop.cfw.utils.*
import com.weetop.cfw.utils.MapUtils
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import com.zhy.view.flowlayout.TagFlowLayout
import kotlinx.android.synthetic.main.activity_workshop_detail.*
import kotlinx.android.synthetic.main.layout_workshop_detail_header.*


/**
 * 厂房详情界面
 */
class WorkshopDetailActivity : CommonBaseActivity(), ViewPager.OnPageChangeListener,
    View.OnClickListener, WorkshopDetailView {

    private lateinit var workshopDetailAdapter: WorkshopDetailAdapter

    private lateinit var workshopDetailHeaderView: View
    private lateinit var workshopDetailLabelFlowLayout: TagFlowLayout

    private lateinit var workshopDetailBanner: XBanner

    private lateinit var baiDuMapView: MapView

    private lateinit var workshopDetailPresenterImp: WorkshopDetailPresenterImp

    private val recommendWorkshopDataList = ArrayList<WorkshopWarehouseDetailBean.ReldataBean>()
    private var bannerList = ArrayList<TestBean>()

    private lateinit var textDetailMap: TextView
    private lateinit var textWorkshopName: TextView
    private lateinit var textViewsNumber: TextView
    private lateinit var textUpdateTime: TextView
    private lateinit var llfenzu: LinearLayout


    //    private lateinit var textInfoType: TextView
//    private lateinit var textWorkshopPrice: TextView
//    private lateinit var textOfficeArc: TextView
//    private lateinit var textVacantArc: TextView
//    private lateinit var textWorkshopArc: TextView
//    private lateinit var textIsSublet: TextView
//    private lateinit var textMinArc: TextView
//    private lateinit var textFloor: TextView
    private lateinit var textMobile: TextView

    //    private lateinit var textWorkshopDetailAddress: TextView
//    private lateinit var textBuildType: TextView
//    private lateinit var textArc: TextViewtextBuildArc
    private lateinit var workShopDescWebView: WebView

    //    private lateinit var textBuildArc: TextView
    private lateinit var textGuDingDianHua: TextView

    //    private lateinit var textFloorcapacity: TextView
    private lateinit var textQizuArea: TextView

    //    private lateinit var textBuildStruct: TextView
//    private lateinit var textPowerdem: TextView
//    private lateinit var textIsAlone: TextView
//    private lateinit var textHasLift: TextView
//    private lateinit var textLandcer: TextView
//    private lateinit var textHousecer: TextView
//    private lateinit var textFheight: TextView
//    private lateinit var textBuildArcLabel: TextView
    private lateinit var textWorkshopNumber: TextView
    private lateinit var textLianXiRenContent: TextView

    private lateinit var textPlantSaleDetailAddress: TextView
    private lateinit var textPlantSaleInfoType: TextView
    private lateinit var textPlantSalePrice: TextView
    private lateinit var textPlantSaleBuildType: TextView
    private lateinit var textPlantSaleZhanDiArc: TextView
    private lateinit var textPlantSaleBuildArc: TextView
    private lateinit var textPlantSaleArc: TextView
    private lateinit var textPlantSaleOfficeArc: TextView
    private lateinit var textPlantSaleVacantArc: TextView
    private lateinit var textPlantSaleIsSublet: TextView
    private lateinit var textPlantSaleMinArc: TextView
    private lateinit var textPlantSaleFloor: TextView
    private lateinit var textPlantSaleFheight: TextView

    private lateinit var llzhengshu: LinearLayout
    private lateinit var tvHouse: TextView
    private lateinit var tvTudi: TextView


    private lateinit var textPlantSaleHasLift: TextView
    private lateinit var textPlantSaleIsAlone: TextView
    private lateinit var textPlantSalePowerdem: TextView
    private lateinit var textPlantSaleBuildStruct: TextView

    //    private lateinit var textPlantSaleColumnspan: TextView
//    private lateinit var textPlantSaleFloorcapacity: TextView
    private lateinit var linearDescriptionOfRealEstateContainer: LinearLayout

    //    private lateinit var linearLandCertificateContainer: LinearLayout
    private lateinit var linearPlantSaleIsSubletContainer: LinearLayout

    private lateinit var imageArrowRightMap: ImageView
    private lateinit var imageArrowRightBlue: ImageView
    private lateinit var imageCallPhone: ImageView

    private lateinit var textWorkshopDetailComplaint: TextView

    private var baiDuMapAppUri: String = ""
    private var baiDuMapWebUrl: String = ""
    private var gaoDeMapAppUri: String = ""
    private var gaoDeMapWebUrl: String = ""

    private var currentLat: Double = 0.0//当前所在位置的纬度
    private var currentLng: Double = 0.0//当前所在位置的经度

    private lateinit var linearPlantSaleContainer: LinearLayout
//    private lateinit var linearWorkshopRentalContainer: LinearLayout

    private var yiXiangKind = 1

    private var fixedTelephone: String = ""//固定电话号码
    private var phoneNumber: String = ""//手机电话号码


    private var totalY: Int = 0

//    private lateinit var locationClient: LocationClient
    //位置监听
//    private var workshopLocationListener: WorkshopLocationListener = WorkshopLocationListener()

    override fun getLayoutId() = R.layout.activity_workshop_detail

    override fun initView(savedInstanceState: Bundle?) {
        ImmersionBar.with(this).transparentStatusBar().fitsSystemWindows(false)
            .statusBarDarkFont(false).init()

        workshopDetailPresenterImp = WorkshopDetailPresenterImp()
        workshopDetailPresenterImp.attachView(this)

        findViewByHeaderView()

        textWorkshopDetailComplaint.setOnClickListener {
            var intent: Intent = Intent(this, TouSuActivity::class.java)
            intent.putExtra("infoId", intent.getIntExtra(WORKSHOP_ID, 0).toString())
            startActivity(intent)
            //  CommonWebViewActivity.startCommonWebViewActivity(this, UrlConstants.complaint_web_url)
        }
        imageArrowRightBlue.setOnClickListener {
            CommonWebViewActivity.startCommonWebViewActivity(this, UrlConstants.complaint_web_url)
        }

        setViewsOnClickListener(
            this,
            imageWorkshopDetailBack,
            textWorkshopDetailBack,
            imageWorkshopDetailBackOther,
            textWorkshopDetailBackOther,
            imageCallPhone,
            textDetailMap,
            imageArrowRightMap,
            imageWorkshopHomePage,
            imageWorkshopHomePageOther,
            imageMessageLogoOther,
            imageMessageLogo,
            relativeContactMerchantsContainer,
            relativeOnlineServiceContainer
        )

        workshopDetailRV.addOnScrollListener(object : RecyclerView.OnScrollListener() {
            override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
                super.onScrolled(recyclerView, dx, dy)
                totalY += dy
                if (totalY > SizeUtils.dp2px(230F)) {
                    relativeWorkshopDetail.visibility = View.INVISIBLE
                    relativeWorkshopDetailOther.visibility = View.VISIBLE
                    ImmersionBar.with(this@WorkshopDetailActivity).transparentStatusBar()
                        .fitsSystemWindows(true, android.R.color.white)
                        .statusBarDarkFont(true).init()
                } else {
                    relativeWorkshopDetail.visibility = View.VISIBLE
                    relativeWorkshopDetailOther.visibility = View.INVISIBLE
                    ImmersionBar.with(this@WorkshopDetailActivity).transparentStatusBar()
                        .fitsSystemWindows(false)
                        .statusBarDarkFont(false).init()
                }
                //  baiDuMapView.onResume()
            }
        })


        //初始化百度地图定位
        // initBaiDuLocation()
    }

    var isShow = false

    private fun checkLookPermission(workshopWarehouseDetailBean: WorkshopWarehouseDetailBean) {
        //if (MMKVUtils.getToken() != "") {
        RxJavaUtils.useInAppCompatActivityOnDestory(
            RetrofitUtils.getApi().checkPermission(
                MMKVUtils.getToken(),
                intent.getIntExtra(WORKSHOP_ID, 0)
            ),
            this,
            object :
                RxJavaCallBack<PermisssionBean>() {
                @SuppressLint("SetTextI18n")
                override fun onSuccess(t: PermisssionBean?) {
                    if (t != null) {
                        isShow = t.ishow == 1
                        if (isShow) {
                            textLianXiRenContent.text = workshopWarehouseDetailBean.linkman//联系人

                            textGuDingDianHua.text = workshopWarehouseDetailBean.phone//固定电话

                            textMobile.text = workshopWarehouseDetailBean.mobile//手机号码
                        } else {
                            textLianXiRenContent.text = workshopWarehouseDetailBean.linkman//联系人
                            textGuDingDianHua.text = "*******"
                            textMobile.text = workshopWarehouseDetailBean.mobile.substring(
                                0,
                                3
                            ) + "****" + workshopWarehouseDetailBean.mobile.substring(
                                workshopWarehouseDetailBean.mobile.length - 4,
                                workshopWarehouseDetailBean.mobile.length
                            )

                        }
                    }
                }

                override fun onErrorResponse(throwable: Throwable?) {
                    super.onErrorResponse(throwable)
                }

                override fun onRequestError(t: PermisssionBean?) {
                    super.onRequestError(t)
                }

            })
        /* } else {
             textLianXiRenContent.text = workshopWarehouseDetailBean.linkman//联系人
             textGuDingDianHua.text = "*******"
             textMobile.text = workshopWarehouseDetailBean.mobile.substring(
                 0,
                 3
             ) + "****" + workshopWarehouseDetailBean.mobile.substring(
                 workshopWarehouseDetailBean.mobile.length - 4,
                 workshopWarehouseDetailBean.mobile.length
             )

         }*/
    }

    override fun initData(savedInstanceState: Bundle?) {
        WebViewSettingUtils.initWebView(workShopDescWebView)

        workshopDetailAdapter =
            WorkshopDetailAdapter(R.layout.layout_work_shop_detail_item, recommendWorkshopDataList)
        workshopDetailAdapter.setOnItemClickListener { _, _, position ->
            startWorkshopDetailActivity(
                this,
                recommendWorkshopDataList[position].infoid,
                yiXiangKind
            )
        }
        workshopDetailAdapter.setHeaderView(workshopDetailHeaderView)
        workshopDetailRV.adapter = workshopDetailAdapter

        yiXiangKind = intent.getIntExtra(YI_XIANG_KIND, 1)

        if (MMKVUtils.getToken() != "") {
            //ToastUtils.showShort(MMKVUtils.getToken())
            workshopDetailPresenterImp.uploadUserRentSaleBrowseRecordData(
                this,
                intent.getIntExtra(WORKSHOP_ID, 0).toString()
            )
        }

        workshopDetailPresenterImp.getWorkshopDetailData(this, intent.getIntExtra(WORKSHOP_ID, 0))
    }

    override fun onResume() {
        super.onResume()
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        baiDuMapView.onResume()
        // workshopDetailPresenterImp.getWorkshopDetailData(this, intent.getIntExtra(WORKSHOP_ID, 0))
    }

    override fun onPause() {
        super.onPause()
        //在activity执行onPause时执行mMapView. onPause ()，实现地图生命周期管理
        baiDuMapView.onPause()
    }

    override fun onDestroy() {
        super.onDestroy()
        workshopDetailPresenterImp.detachView()
        WebViewSettingUtils.destoryWebView(
            workShopDescWebView,
            linearDescriptionOfRealEstateContainer
        )
        baiDuMapView.onDestroy()
    }


    /**
     * 展示拨打电话的底部对话框
     */
    private fun showCallPhoneBottomMenu() {
        if (fixedTelephone == "") {
            BottomMenu.show(this, arrayOf("拨打手机号码：${phoneNumber}")) { text, index ->
                SystemActivityUtils.startDialActivityWithPhoneNumber(phoneNumber)
            }
        } else {
            BottomMenu.show(
                this,
                arrayOf("拨打固定电话：${fixedTelephone}", "拨打手机号码：${phoneNumber}")
            ) { text, index ->
                if (index == 0) {
                    SystemActivityUtils.startDialActivityWithPhoneNumber(fixedTelephone)
                } else {
                    SystemActivityUtils.startDialActivityWithPhoneNumber(phoneNumber)
                }
            }
        }
    }

    /**
     * 展示使用哪一款地图APP的底部对话框
     */
    private fun showChooseMapBottomMenu() {
        BottomMenu.show(
            this@WorkshopDetailActivity,
            arrayOf("百度地图", "高德地图")
        ) { text, index ->
            //返回参数 text 即菜单名称，index 即菜单索引
            if (index == 0) {
                if (MapUtils.isBaiDuMapAlreadyInstalled()) {//如果已经安装百度地图，则调起百度地图
                    val i1 = Intent()
                    // 地址解析
                    i1.data = Uri.parse(baiDuMapAppUri)
                    ActivityUtils.startActivity(i1)
                } else {//调起百度地图网页版
                    SystemActivityUtils.startSystemBrowserActivity(baiDuMapWebUrl)
                }
            } else {
                if (MapUtils.isGaoDeMapAlreadyInstalled()) {//如果已经安装高德地图，这调起高德地图
                    val uri = Uri.parse(gaoDeMapAppUri)
                    ActivityUtils.startActivity(Intent(Intent.ACTION_VIEW, uri))
                } else {//调起高德地图网页版
                    SystemActivityUtils.startSystemBrowserActivity(gaoDeMapWebUrl)
                }
            }
        }
    }

    override fun onPageScrollStateChanged(state: Int) {

    }

    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {

    }

    override fun onPageSelected(position: Int) {
        val bannerNumber = bannerList.size
        LogUtils.d("数字指示器", "${position + 1}/${bannerList.size}")
        textNumberIndicator.text = "${position % bannerNumber + 1}/${bannerNumber}"
    }

    companion object {
        private const val WORKSHOP_ID = "WORKSHOP_ID"
        private const val YI_XIANG_KIND = "YI_XIANG_KIND"
        fun startWorkshopDetailActivity(context: Context, infoid: Int, yiXiangKind: Int) {
            val intent = Intent(context, WorkshopDetailActivity::class.java)
            intent.putExtra(WORKSHOP_ID, infoid)
            intent.putExtra(YI_XIANG_KIND, yiXiangKind)
            ActivityUtils.startActivity(intent)
        }
    }

    override fun onClick(p0: View?) {
        when (p0?.id) {
            R.id.imageWorkshopDetailBack, R.id.textWorkshopDetailBack, R.id.imageWorkshopDetailBackOther, R.id.textWorkshopDetailBackOther -> ActivityUtils.finishActivity(
                this
            )
            R.id.imageCallPhone -> {
//                if (LogInUtils.userIsLogIn())
//                    if (isShow) {
//                        showCallPhoneBottomMenu()
//                    } else {
//                        var str = intent.getIntExtra(WORKSHOP_ID, 0).toString()
//                        MessageDialog.show(this, "提示", "没有查看权限是否购买？", "立即购买", "取消")
//                            .setOnOkButtonClickListener { baseDialog, v ->
//                                var intent = Intent(
//                                    this@WorkshopDetailActivity,
//                                    PurchaseMembershipActivity::class.java
//                                )
//                                intent.putExtra("infoid", str)
//                                startActivity(intent)
//                                false
//                            }
//                    }
                if (isShow) {
                    showCallPhoneBottomMenu()
                } else {
                    if (LogInUtils.userIsLogIn()) {
                        var str = intent.getIntExtra(WORKSHOP_ID, 0).toString()
                        MessageDialog.show(this, "提示", "没有查看权限是否购买？", "立即购买", "取消")
                            .setOnOkButtonClickListener { baseDialog, v ->
                                var intent =
                                    Intent(
                                        this@WorkshopDetailActivity,
                                        PurchaseMembershipActivity::class.java
                                    )
                                intent.putExtra("infoid", str)
                                startActivity(intent)
                                false
                            }
                    }
                }
            }
            R.id.textDetailMap, R.id.imageArrowRightMap -> {
                if (MapUtils.isBaiDuMapAlreadyInstalled()) {//如果已经安装百度地图，则调起百度地图
                    val i1 = Intent()
                    // 地址解析
                    i1.data = Uri.parse(baiDuMapAppUri)
                    ActivityUtils.startActivity(i1)
                } else {//调起百度地图网页版
                    SystemActivityUtils.startSystemBrowserActivity(baiDuMapWebUrl)
                }
            }
            R.id.imageMessageLogo, R.id.imageMessageLogoOther -> MainActivity.startMainActivity(
                this,
                2
            )
            R.id.imageWorkshopHomePage, R.id.imageWorkshopHomePageOther -> MainActivity.startMainActivity(
                this,
                0
            )
            R.id.relativeOnlineServiceContainer -> ActivityUtils.startActivity(
                IntentUtils.getDialIntent(
                    Constants.CUSTOMER_SERVICE_PHONE_NUMBER
                )
            )
            R.id.relativeContactMerchantsContainer -> {
//                if (LogInUtils.userIsLogIn())
                if (isShow) {
                    showCallPhoneBottomMenu()
                } else {
                    if (LogInUtils.userIsLogIn()) {
                        var str = intent.getIntExtra(WORKSHOP_ID, 0).toString()
                        MessageDialog.show(this, "提示", "没有查看权限是否购买？", "立即购买", "取消")
                            .setOnOkButtonClickListener { baseDialog, v ->
                                var intent =
                                    Intent(
                                        this@WorkshopDetailActivity,
                                        PurchaseMembershipActivity::class.java
                                    )
                                intent.putExtra("infoid", str)
                                startActivityForResult(intent, 999)
                                false
                            }
                    }
                }
            }
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == 88) {
            isShow = true
        }
    }


    /**
     * 厂房详情数据获取成功
     */
    @SuppressLint("NewApi")
    override fun workShopGetSuccess(workshopWarehouseDetailBean: WorkshopWarehouseDetailBean?) {
        if (workshopWarehouseDetailBean != null) {
            checkLookPermission(workshopWarehouseDetailBean)
            textWorkshopNumber.text = workshopWarehouseDetailBean.infoid.toString()

            textWorkshopName.text = workshopWarehouseDetailBean.title

            textViewsNumber.text = "浏览次数：${workshopWarehouseDetailBean.view}次"
            if (workshopWarehouseDetailBean.update != "")
                textUpdateTime.text = "更新时间：${workshopWarehouseDetailBean.update.split(" ")[0]}"

            val labelList = workshopWarehouseDetailBean.labkey.split(",")
            val workshopLabelList = ArrayList<String>()
            for (itemLabel in labelList) {
                if (itemLabel.isNotBlank()) {
                    workshopLabelList.add(itemLabel)
                }
            }

            workshopDetailLabelFlowLayout.adapter = object : TagAdapter<String>(workshopLabelList) {
                override fun getView(parent: FlowLayout?, position: Int, t: String?): View {
                    val textItemWorkshopDescFlowLayoutView =
                        LayoutInflater.from(this@WorkshopDetailActivity)
                            .inflate(R.layout.layout_item_workshop_desc_flow, parent, false)
                    val textItemWorkshopDesc =
                        textItemWorkshopDescFlowLayoutView.findViewById<SuperTextView>(R.id.textItemWorkshopDesc)
                    textItemWorkshopDesc.text = labelList[position]
                    return textItemWorkshopDescFlowLayoutView
                }
            }

            recommendWorkshopDataList.addAll(workshopWarehouseDetailBean.reldata)
            workshopDetailAdapter.notifyDataSetChanged()

            val buildType = workshopWarehouseDetailBean.typename.split(",")
            val buildTypeStr = StringBuilder()
            for (item in buildType) {
                buildTypeStr.append("$item ")
            }

            val structType = workshopWarehouseDetailBean.struct.split(",")
            val structTypeStr = StringBuilder()
            for (item in structType) {
                structTypeStr.append("$item ")
            }

            if (workshopWarehouseDetailBean.intid == "2") {//厂房出售和仓库出售
                linearPlantSaleContainer.visibility = View.VISIBLE
//                linearWorkshopRentalContainer.visibility = View.GONE
//                linearLandCertificateContainer.visibility = View.VISIBLE
                llfenzu.visibility = View.GONE
                llzhengshu.visibility = View.VISIBLE
                tvHouse.text = workshopWarehouseDetailBean.housecer
                tvTudi.text = workshopWarehouseDetailBean.landcer
                textPlantSaleDetailAddress.text =
                    "${workshopWarehouseDetailBean.areaname}-${workshopWarehouseDetailBean.address}"//详细地址

                textPlantSaleInfoType.text = workshopWarehouseDetailBean.intname//信息类型

                textPlantSalePrice.text =
                    "${workshopWarehouseDetailBean.price}${workshopWarehouseDetailBean.punit}"//价格

                textPlantSaleBuildType.text = buildTypeStr.toString()//建筑类型

                textPlantSaleZhanDiArc.text = "${workshopWarehouseDetailBean.coverarea}㎡"

                textPlantSaleBuildArc.text = "${workshopWarehouseDetailBean.totalarea}㎡"

                textPlantSaleArc.text = "${workshopWarehouseDetailBean.workarea}㎡"

                textQizuArea.text = "${workshopWarehouseDetailBean.minarea}㎡"


                textPlantSaleOfficeArc.text = "${workshopWarehouseDetailBean.officearea}㎡"

                textPlantSaleVacantArc.text = "${workshopWarehouseDetailBean.vacantarea}㎡"

                textPlantSaleIsSublet.text = workshopWarehouseDetailBean.sublet


                textPlantSaleFloor.text = "${workshopWarehouseDetailBean.floor}层"

                textPlantSaleFheight.text = "${workshopWarehouseDetailBean.fheight}米"



                textPlantSaleHasLift.text = workshopWarehouseDetailBean.lift

                textPlantSaleIsAlone.text = workshopWarehouseDetailBean.alone

                textPlantSalePowerdem.text = "${workshopWarehouseDetailBean.powerdem}kva"

                textPlantSaleBuildStruct.text = structTypeStr.toString()//建筑结构
                textPlantSaleBuildArcLabel.text = "建筑面积"


            } else {//厂房出租和仓库出租
                linearPlantSaleContainer.visibility = View.VISIBLE
                textPlantSaleBuildArcLabel.text = "出租总面积"
                textQizuArea.text = "${workshopWarehouseDetailBean.minarea}㎡"

                llfenzu.visibility = View.VISIBLE
                llzhengshu.visibility = View.GONE


                textPlantSaleDetailAddress.text =
                    "${workshopWarehouseDetailBean.areaname}-${workshopWarehouseDetailBean.address}"//详细地址

                textPlantSaleInfoType.text = workshopWarehouseDetailBean.intname//信息类型

                textPlantSalePrice.text =
                    "${workshopWarehouseDetailBean.price}${workshopWarehouseDetailBean.punit}"//价格

                textPlantSaleBuildType.text = buildTypeStr.toString()//建筑类型

                textPlantSaleZhanDiArc.text = "${workshopWarehouseDetailBean.coverarea}㎡"

                textPlantSaleBuildArc.text = "${workshopWarehouseDetailBean.totalarea}㎡"

                textPlantSaleArc.text = "${workshopWarehouseDetailBean.workarea}㎡"

                textPlantSaleOfficeArc.text = "${workshopWarehouseDetailBean.officearea}㎡"

                textPlantSaleVacantArc.text = "${workshopWarehouseDetailBean.vacantarea}㎡"

                textPlantSaleIsSublet.text = workshopWarehouseDetailBean.sublet


                textPlantSaleFloor.text = "${workshopWarehouseDetailBean.floor}层"

                textPlantSaleFheight.text = "${workshopWarehouseDetailBean.fheight}米"



                textPlantSaleHasLift.text = workshopWarehouseDetailBean.lift

                textPlantSaleIsAlone.text = workshopWarehouseDetailBean.alone

                textPlantSalePowerdem.text = "${workshopWarehouseDetailBean.powerdem}kva"

                textPlantSaleBuildStruct.text = structTypeStr.toString()//建筑结构

            }
            var str = StringBuffer()
            str.append("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><body><p style=\"word-break:break-all; padding:12px;\">")
                .append(String(EncodeUtils.base64Decode(workshopWarehouseDetailBean.content)))
                .append("</p></body></html>")

            var url: String = ""
            if (!(str.contains("http:") || str.contains("https:"))) {
                url = ReplaceUtils.getReplace(str.toString())
            }

            workShopDescWebView.loadData(url.toString(), "text/html; charset=UTF-8", null)//房产描述

            fixedTelephone = workshopWarehouseDetailBean.phone
            phoneNumber = workshopWarehouseDetailBean.mobile

            val lat =
                if (workshopWarehouseDetailBean.maplat == "") 30.267556 else workshopWarehouseDetailBean.maplat.toDouble()

            val lng =
                if (workshopWarehouseDetailBean.maplng == "") 120.236782 else workshopWarehouseDetailBean.maplng.toDouble()

//            val lat = workshopWarehouseDetailBean.maplat.toDouble()
//            val lng = workshopWarehouseDetailBean.maplng.toDouble()


            val imgBannerArray = workshopWarehouseDetailBean.imglist.split(",")
            //LogUtils.eTag("imgBannerArray", imgBannerArray)
            bannerList = ArrayList()
            for (i in imgBannerArray.indices) {
                bannerList.add(TestBean("${UrlConstants.baseUrl}${imgBannerArray[i]}"))
            }
//            LogUtils.eTag("bannerList", bannerList)
            workshopDetailBanner.setBannerData(
                R.layout.banner_layout,
                bannerList
            )

            workshopDetailBanner.loadImage { _, _, view, position ->
                val textWorkshopBannerItemImage =
                    view.findViewById<ImageView>(R.id.textWorkshopBannerItemImage)
                Glide.with(this).load(bannerList[position].a).apply(
                    RequestOptions().error(R.drawable.emptypic)/*.apply(
                        RequestOptions().transform(CircleCrop())
                    )*/.placeholder(R.drawable.emptypic)
                ).into(textWorkshopBannerItemImage)
                // textWorkshopBannerItemImage.setUrlImage(bannerList[position].a)
            }

            textNumberIndicator.text = "1/${bannerList.size}"

            workshopDetailBanner.viewPager.addOnPageChangeListener(this)

            textDetailAddress.text = workshopWarehouseDetailBean.address
            textCityAddress.text = workshopWarehouseDetailBean.areaname

            val baiDuLatLng = LatLng(lat, lng)
            val geoCoder = GeoCoder.newInstance()
            geoCoder.setOnGetGeoCodeResultListener(object : OnGetGeoCoderResultListener {

                override fun onGetGeoCodeResult(p0: GeoCodeResult?) {

                }


                override fun onGetReverseGeoCodeResult(reverseGeoCodeResult: ReverseGeoCodeResult) {
                    if (reverseGeoCodeResult == null || reverseGeoCodeResult.error != SearchResult.ERRORNO.NO_ERROR) {
                        // 没有检测到结果
                        return
                    }
                    val addressDetail = reverseGeoCodeResult.addressDetail
                    baiDuMapAppUri =
                        "baidumap://map/geocoder?src=andr.baidu.openAPIdemo&address=$${addressDetail.province}${addressDetail.city}${addressDetail.district}${addressDetail.town}${addressDetail.street}${addressDetail.streetNumber}"
                }
            })
            geoCoder.reverseGeoCode(ReverseGeoCodeOption().location(baiDuLatLng))
            baiDuMapWebUrl =
                "http://api.map.baidu.com/geocoder?location=${lat},${lng}&coord_type=gcj02&output=html&src=webapp.baidu.openAPIdemo"
            gaoDeMapAppUri =
                "amapuri://route/plan/?sid=&slat=${lat}&slon=${lng}&sname=${LocationUtils.getLocality(
                    lat,
                    lng
                )}&did=&dlat=${currentLat}&dlon=${currentLng}&dname=${LocationUtils.getLocality(
                    currentLat,
                    currentLng
                )}&dev=0&t=0"
            gaoDeMapWebUrl =
                "http://m.amap.com/navigation/carmap/saddr=${currentLng},${currentLat},${LocationUtils.getLocality(
                    currentLat,
                    currentLng
                )}&daddr=${lng},${lat},${LocationUtils.getLocality(lat, lng)}&sort=dist"

            var msg = Message()
            msg.what = 1
            msg.obj = "${lat},${lng}"
            hadleer.sendMessageDelayed(msg, 5000)
        }

    }

    var hadleer = Handler {
        if (it.what == 1) {
            var lat = it.obj.toString().split(",")[0].toDouble()
            var lng = it.obj.toString().split(",")[1].toDouble()
            /*val locData = MyLocationData.Builder()
                .accuracy(10F)
                .latitude(lat)
                .longitude(lng).build()
            baiDuMapView.map.setMyLocationData(locData)*/

            val ll = LatLng(lat, lng)
            val builder = MapStatus.Builder()
            builder.target(ll).zoom(18.0f)
            baiDuMapView.map.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()))
            val bitmap = fromResource(R.drawable.iv_location);
            baiDuMapView.map.setCompassEnable(false)
            //构建MarkerOption，用于在地图上添加Marker
            val option = MarkerOptions()
                .position(ll)
                .icon(bitmap)
            //在地图上添加Marker，并显示
            baiDuMapView.map.addOverlay(option)
            baiDuMapView.visibility = View.VISIBLE
        }
        false
    }

    /**
     * 推荐厂房数据获取成功
     */
    override fun recommendWorkshopDataGetSuccess(leaseSaleBrowsingRecordBean: LeaseSaleBrowsingRecordBean?) {
        if (leaseSaleBrowsingRecordBean != null) {
//            recommendWorkshopDataList.addAll(leaseSaleBrowsingRecordBean.data)
//            workshopDetailAdapter.notifyDataSetChanged()
        }
    }

    /**
     * 查找头布局控件
     */
    override fun findViewByHeaderView() {
        //初始化头布局
        workshopDetailHeaderView = View.inflate(this, R.layout.layout_workshop_detail_header, null)
        //初始化头布局的控件
        linearPlantSaleContainer =
            workshopDetailHeaderView.findViewById(R.id.linearPlantSaleContainer)

        workshopDetailLabelFlowLayout =
            workshopDetailHeaderView.findViewById(R.id.workshopDetailLabelFlowLayout)
        linearDescriptionOfRealEstateContainer =
            workshopDetailHeaderView.findViewById(R.id.linearDescriptionOfRealEstateContainer)
        baiDuMapView = workshopDetailHeaderView.findViewById(R.id.baiDuMapView)
        workshopDetailBanner = workshopDetailHeaderView.findViewById(R.id.workshopDetailBanner)
//        textBuildArcLabel = workshopDetailHeaderView.findViewById(R.id.textBuildArcLabel)
        textDetailMap = workshopDetailHeaderView.findViewById(R.id.textDetailMap)
        imageArrowRightMap = workshopDetailHeaderView.findViewById(R.id.imageArrowRightMap)
        imageArrowRightBlue = workshopDetailHeaderView.findViewById(R.id.imageArrowRightBlue)
        textWorkshopDetailComplaint =
            workshopDetailHeaderView.findViewById(R.id.textWorkshopDetailComplaint)
        imageCallPhone = workshopDetailHeaderView.findViewById(R.id.imageCallPhone)
        textWorkshopName = workshopDetailHeaderView.findViewById(R.id.textWorkshopName)
        textViewsNumber = workshopDetailHeaderView.findViewById(R.id.textViewsNumber)
        textUpdateTime = workshopDetailHeaderView.findViewById(R.id.textUpdateTime)

        workShopDescWebView = workshopDetailHeaderView.findViewById(R.id.workShopDescWebView)
        textMobile = workshopDetailHeaderView.findViewById(R.id.textMobile)
        textGuDingDianHua = workshopDetailHeaderView.findViewById(R.id.textGuDingDianHua)
        textLianXiRenContent = workshopDetailHeaderView.findViewById(R.id.textLianXiRenContent)

        textWorkshopNumber = workshopDetailHeaderView.findViewById(R.id.textWorkshopNumber)

        textPlantSaleDetailAddress =
            workshopDetailHeaderView.findViewById(R.id.textPlantSaleDetailAddress)
        textPlantSaleInfoType = workshopDetailHeaderView.findViewById(R.id.textPlantSaleInfoType)
        textPlantSalePrice = workshopDetailHeaderView.findViewById(R.id.textPlantSalePrice)
        textPlantSaleBuildType = workshopDetailHeaderView.findViewById(R.id.textPlantSaleBuildType)
        textPlantSaleZhanDiArc = workshopDetailHeaderView.findViewById(R.id.textPlantSaleZhanDiArc)
        textPlantSaleBuildArc = workshopDetailHeaderView.findViewById(R.id.textPlantSaleBuildArc)
        textPlantSaleArc = workshopDetailHeaderView.findViewById(R.id.textPlantSaleArc)
        textPlantSaleOfficeArc = workshopDetailHeaderView.findViewById(R.id.textPlantSaleOfficeArc)
        textPlantSaleVacantArc = workshopDetailHeaderView.findViewById(R.id.textPlantSaleVacantArc)
        textPlantSaleIsSublet = workshopDetailHeaderView.findViewById(R.id.textPlantSaleIsSublet)
        linearPlantSaleIsSubletContainer =
            workshopDetailHeaderView.findViewById(R.id.linearPlantSaleIsSubletContainer)
        textPlantSaleFheight = workshopDetailHeaderView.findViewById(R.id.textPlantSaleFheight)
//        textPlantSaleMinArc = workshopDetailHeaderView.findViewById(R.id.textPlantSaleMinArc)
        textPlantSaleFloor = workshopDetailHeaderView.findViewById(R.id.textPlantSaleFloor)
        textQizuArea = workshopDetailHeaderView.findViewById(R.id.textQizuArea)
        llzhengshu = workshopDetailHeaderView.findViewById(R.id.llzhengshu)
        tvHouse = workshopDetailHeaderView.findViewById(R.id.tvHouse)
        tvTudi = workshopDetailHeaderView.findViewById(R.id.tvTudi)


        textPlantSaleHasLift = workshopDetailHeaderView.findViewById(R.id.textPlantSaleHasLift)
        textPlantSaleIsAlone = workshopDetailHeaderView.findViewById(R.id.textPlantSaleIsAlone)
        textPlantSalePowerdem = workshopDetailHeaderView.findViewById(R.id.textPlantSalePowerdem)
        textPlantSaleBuildStruct =
            workshopDetailHeaderView.findViewById(R.id.textPlantSaleBuildStruct)

        llfenzu =
            workshopDetailHeaderView.findViewById(R.id.llfenzu)
    }
}
